#include "game.hpp"

using namespace std;

game::game()
{
    SWidth = 640;
    SHeight = 480;
    SBpp = 32;
    quit = false;
    STitle = "Project Lyons 0.0.1";
    init(screen, SWidth, SHeight, STitle);
    screen = SDL_SetVideoMode( SWidth, SHeight, 32, SDL_SWSURFACE );
    background = load_image("largeMap.bmp");
    p = player(40,40);
}

game::game(int x, int y)
{
    SWidth = x;
    SHeight = y;
    SBpp = 32;
    STitle = "Project Lyons 0.0.1";

    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "Unable to init SDL: %s\n", SDL_GetError() );
    }

    screen = SDL_SetVideoMode( SWidth, SHeight, SBpp, SDL_SWSURFACE );
    if ( !screen )
    {
    }

    SDL_WM_SetCaption( STitle.c_str(), NULL );
}
void game::run()
{
    int counter = 0; //temp
    while(quit == false)
    {
        if(SDL_PollEvent( &event ))
        {
            if(event.type == SDL_QUIT)
            {
                quit = true;
            }
        }
        Uint8 *keystates = SDL_GetKeyState( NULL );
        p.move(keystates[ SDLK_UP ] || keystates[ SDLK_w ], keystates[ SDLK_DOWN ] || keystates[ SDLK_s ], keystates[ SDLK_LEFT ] || keystates[ SDLK_a ], keystates[ SDLK_RIGHT] || keystates[ SDLK_d ] );

        draw();
    }
}
void game::draw()
{
    apply_surface(0,0,background,screen);
    p.draw(screen);
    SDL_Flip(screen);
}
